package restaurant.agents;

import jade.core.Agent;
import jade.domain.DFService;
import jade.domain.FIPAException;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.domain.FIPAAgentManagement.ServiceDescription;

import java.util.ArrayDeque;
import java.util.ArrayList;

import restaurant.behaviours.kitchen.KitchenCookBehaviour;
import restaurant.behaviours.kitchen.KitchenReceiveBehaviour;
import restaurant.core.Request;
import restaurant.core.Restaurant;

public class KitchenAgent extends Agent {
	
	private static final long serialVersionUID = -3158771002445792027L;
	public ArrayDeque<Request> toCook;
	public Restaurant restaurant;
	private int experience = 0;
	public int bound = 1000;
	public ArrayList<String> queue;
	
	private int score = 0;
	
	@Override
	protected void setup() {
		this.restaurant = Restaurant.getInstance();
		
		this.toCook = new ArrayDeque<Request>();
		this.queue = new ArrayList<String>();
		
		DFAgentDescription agentDescription = new DFAgentDescription();
		agentDescription.setName(getAID());
		
		ServiceDescription serviceDescription = new ServiceDescription();
		serviceDescription.setType("kitchen");
		serviceDescription.setName("JADE-restaurant");
		
		agentDescription.addServices(serviceDescription);
		try {
			DFService.register(this, agentDescription);
		} catch (FIPAException e) {
			e.printStackTrace();
		}
		
		addBehaviour(new KitchenReceiveBehaviour(this));
		addBehaviour(new KitchenCookBehaviour(this));
	}
	
	@Override
	protected void takeDown() {
		try {
			DFService.deregister(this);
		} catch (FIPAException e) {
		}
		System.out.println("KitchenAgent: Agente " + getLocalName() + " terminato!");
	}
	
	public void setScore(int score) {
		this.score = score;
		
		this.restaurant.kitchenAgentScore = this.score;
	}
	
	public int getScore() {
		return score;
	}
	
	public int getExperience() {
		return experience;
	}
	
	public void setExperience(int experience) {
		this.experience = experience;
	}
}